
**************************************************************************************************;
**************************************************************************************************;
*This do file generates Appendix Table A-2: Authoritarian Parenting and Peer Environment Across Schools;
**************************************************************************************************;
**************************************************************************************************;

*Set of controls for the regression models;
global controls "i.gender i.race age educ_mother_miss d_educ_mother_miss family_income_miss d_family_income_miss "

*Open data;
use $scratch/final_skills_peers.dta, clear

gen income_inequality_school = .
gen income_median_school = .
levelsof idschool, local(levels) 
foreach s of local levels {

qui sum family_income if idschool==`s', de
replace income_median_school = r(p50)/10000 if idschool==`s'
qui sum family_income if idschool==`s', de
replace income_inequality_school = r(p90)/r(p10) if idschool==`s'

}

recode H1WP2 (0=1) (1=0) , gen(authoritarian_parents)

replace race = 4 if race==.
replace gender = 3 if gender==.


gen family_income_miss = family_income 
qui sum family_income
replace family_income_miss = r(mean) if family_income==.

gen d_family_income_miss = 0
replace d_family_income_miss = 1 if family_income==.

gen educ_mother_miss = .
replace  educ_mother_miss = educ_mother if educ_mother!=.
replace educ_mother_miss = 0 if educ_mother==.

gen d_educ_mother_miss = 0
replace d_educ_mother_miss =1 if educ_mother==.


*Store the sample;
qui reg author income_median_school income_inequality_school $controls  , cluster(idschool) 
gen temp_sampl = e(sample)

label var income_median_school "\shortstack{ Median Family Income \\ at School }" 
label var income_inequality_school "\shortstack{  90-10 Family Income \\ at School }" 

reg author income_median_school income_inequality_school if temp_sampl , cluster(idschool) 
est store a1_est
qui sum  author if e(sample)
qui estadd scalar mean = r(mean)
estadd local s_fe "No": a1_est

reg author income_median_school income_inequality_school $controls if temp_sampl , cluster(idschool) 
est store a2_est
qui sum  author if e(sample)
qui estadd scalar mean = r(mean)
estadd local s_fe "Yes": a2_est


#delimit ;
esttab a1_est a2_est   using "$tables/ps_friends_school.tex", nonotes nocons  replace label 
 starlevels(* 0.10 ** 0.05 *** 0.01) b(%5.3f) se not keep(income_median_school income_inequality_school )
 stats(mean N N_clust s_fe , fmt(%9.3f %9.0g %9.0g %s) 
 labels("Mean Dependent Var." "Observations" "Clusters" "Controls")) 
  prehead( " \begin{tabular}{lcc} \hline \hline \\[0.3cm] ")  posthead(" &  \multicolumn{2}{c}{ Authoritarian }   \\ \hline \\[0.3cm]")
 postfoot("\hline \hline \end{tabular}")  
 nomtitles
 ;
#delimit cr;
